package com.ruoyi.web.controller.organization;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.organization.domain.vo.ChangeFamilyScore;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.organization.domain.BizFamily;
import com.ruoyi.organization.service.IBizFamilyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 家庭积分Controller
 * 
 * @author ruoyi
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/organization/family")
public class BizFamilyController extends BaseController
{
    @Autowired
    private IBizFamilyService bizFamilyService;

    /**
     * 查询家庭积分列表
     */
    @PreAuthorize("@ss.hasPermi('organization:family:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizFamily bizFamily)
    {
        List<BizFamily> list = bizFamilyService.selectBizFamilyListPage(bizFamily);
        return getDataTable(list);
    }

    /**
     * 导出家庭积分列表
     */
    @PreAuthorize("@ss.hasPermi('organization:family:export')")
    @Log(title = "家庭积分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizFamily bizFamily)
    {
        List<BizFamily> list = bizFamilyService.selectBizFamilyList(bizFamily,"type");
        ExcelUtil<BizFamily> util = new ExcelUtil<BizFamily>(BizFamily.class);
        util.exportExcel(response, list, "家庭积分数据");
    }

    /**
     * 获取家庭积分详细信息
     */
    @PreAuthorize("@ss.hasPermi('organization:family:query')")
    @GetMapping(value = "/{familyId}")
    public AjaxResult getInfo(@PathVariable("familyId") Long familyId)
    {
        return success(bizFamilyService.selectBizFamilyByFamilyId(familyId));
    }

    /**
     * 新增家庭积分
     */
    @PreAuthorize("@ss.hasPermi('organization:family:add')")
    @Log(title = "家庭积分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizFamily bizFamily)
    {
        bizFamily.setCreateBy(getUsername());
        return toAjax(bizFamilyService.insertBizFamily(bizFamily));
    }

    /**
     * 修改家庭积分
     */
    @PreAuthorize("@ss.hasPermi('organization:family:edit')")
    @Log(title = "家庭积分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizFamily bizFamily)
    {
        bizFamily.setUpdateBy(getUsername());
        return toAjax(bizFamilyService.updateBizFamily(bizFamily));
    }

    /**
     * 调整家庭积分
     * @param changeFamilyScore
     * @return
     */
     @PreAuthorize("@ss.hasPermi('organization:family:changeScore')")
     @Log(title = "调整家庭积分", businessType = BusinessType.UPDATE)
     @PostMapping("/changeScore")
     public AjaxResult changeScore(@RequestBody ChangeFamilyScore changeFamilyScore)
     {
         return toAjax(bizFamilyService.changeScore(changeFamilyScore));
     }
    /**
     * 删除家庭积分
     */
    @PreAuthorize("@ss.hasPermi('organization:family:remove')")
    @Log(title = "家庭积分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{familyIds}")
    public AjaxResult remove(@PathVariable Long[] familyIds)
    {
        return toAjax(bizFamilyService.deleteBizFamilyByFamilyIds(familyIds));
    }
}
